package com.itboye.ihomebank.home;

import java.util.Observable;
import java.util.Observer;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.base.BaseOtherActivity;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.constants.SPContants;
import com.itboye.ihomebank.presenter.HousePresenter;
import com.itboye.ihomebank.util.ByAlert;
import com.itboye.ihomebank.util.ChooseTimePopwindow;
import com.itboye.ihomebank.util.SPUtils;
import com.itboye.ihomebank.util.ChooseTimePopwindow.onFinishedLisenter;
import com.itboye.ihomebank.util.TimesUtils;

public class ActivityYuYueKanfang extends BaseOtherActivity implements
		onFinishedLisenter, Observer {

	Button begin_time, end_time, ok;
	EditText beizhu;
	HousePresenter housePresenter;
	ImageView close_icon;
	TextView add_shap_title_tv;
	private String status;
	private String uid;
	private String houseNo;

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ok:
			String startT = begin_time.getText().toString();
			startT = TimesUtils.getStringToDate(startT) + "";
			String endT = end_time.getText().toString();
			endT = TimesUtils.getStringToDate(endT) + "";
			System.out.println(startT+">?:"+endT);
			String mark = beizhu.getText().toString();
			if (mark.equals("")) {
				ByAlert.alert("请输入备注信息");
				return;
			}
			uid = SPUtils.get(this, null, SPContants.USER_ID, "") + "";
			housePresenter.yuYueKanFang(uid, houseNo, mark, "0", startT, endT);
			break;
		case R.id.begin_time:

			ChooseTimePopwindow startTimePopwindow = new ChooseTimePopwindow(
					this, this, true);
			startTimePopwindow.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.end_time:
			ChooseTimePopwindow endTimePopwindow = new ChooseTimePopwindow(
					this, this, false);
			endTimePopwindow.showAtLocation(v, Gravity.BOTTOM
					| Gravity.CENTER_HORIZONTAL, 0, 0);
			break;
		case R.id.close_icon:
			finish();
			break;
		case R.id.cancel:

		default:
			break;
		}

	}

	@Override
	protected int layout_id() {
		// TODO Auto-generated method stub
		return R.layout.activity_yuyuekanfang;
	}

	@Override
	protected void onInitController() {
		// TODO Auto-generated method stub

	}

	@Override
	protected void onInit() {
		// TODO Auto-generated method stub
		housePresenter = new HousePresenter(this);
		add_shap_title_tv.setText("申请预约");
		houseNo = getIntent().getStringExtra("house_no");
	}

	@Override
	protected void onReadIntent(Bundle bundle) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getBeginTime(String year, String month, String day,
			String hour, String minite) {
		// TODO Auto-generated method stub
		begin_time.setText("开始时间:" + year + "年" + month + "月" + day + "日 "
				+ hour + ":" + minite);
	}

	@Override
	public void getEndTime(String year, String month, String day, String hour,
			String minite) {
		// TODO Auto-generated method stub

		end_time.setText("结束时间:" + year + "年" + month + "月" + day + "日 " + hour
				+ ":" + minite);
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			if (entity.getEventType() == HousePresenter.yuYueKanFang_success) {
				ByAlert.alert(entity.getData());
				finish();
			} else if (entity.getEventType() == HousePresenter.yuYueKanFang_fail) {
				ByAlert.alert(entity.getData());
			}
		}
	}

}
